﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Cotrobaie.Clase
{
    public class TabelSearchuri
    {
        public static string tabelProducts(List<UsersWebService.TipProdus> produse)
        {
            int index = 0;
            string rand1 = String.Empty; string rand2 = String.Empty; string rand3 = String.Empty;
            string rez = "<div style='text-align:center;'><table align='ceter' style='text-align:center;'><tr>";
            for (int i = 0; i < produse.Count(); i++)
            {
                rand1 += "<td><a href='" + produse.ElementAt(i).linkSite + "' target='_parent'><img BORDER='0' src='" + (produse.ElementAt(i).imageLarge != null && produse.ElementAt(i).imageLarge.Length > 0 ? produse.ElementAt(i).imageLarge : (produse.ElementAt(i).imageMedium != null && produse.ElementAt(i).imageMedium.Length > 0 ? produse.ElementAt(i).imageMedium : (produse.ElementAt(i).imageSmall != null && produse.ElementAt(i).imageSmall.Length > 0 ? produse.ElementAt(i).imageSmall : "../images/img.jpg"))) + "' style='max-height:175px; max-width:175px;' /></a></td><td style='width:80px;'><span>&nbsp;</span></td>";
                rand2 += "<td style='width:100px;align:center;padding:5px;vertical-align:text-top;'><a class='blgrlink' href='" + produse.ElementAt(i).linkSite + "' target='_parent' style='font-weight:bold;'>" + (produse.ElementAt(i).name.Length > 60 ? (produse.ElementAt(i).name.Substring(0, 60) + " ...") : produse.ElementAt(i).name) + "</a></td><td style='width:80px;'><span>&nbsp;</span></td>";
                rand3 += "<td style='align:center;padding:3px;font-size:12px;color:#ffffff;'><span>$" + String.Format("{0:0,0.00}", (double)produse.ElementAt(i).Price) + "</span></td><td style='width:80px;'><span>&nbsp;</span></td>";
                if (i % 4 == 3 || i == produse.Count() - 1)
                {
                    rez += rand1 + "</tr><tr>";
                    rez += rand2 + "</tr><tr>";
                    rez += rand3 + "</tr><tr><td><span>&nbsp;</span></td></tr>";
                    if (i < produse.Count() - 1) rez += "<tr>";
                    rand1 = rand2 = rand3 = String.Empty;
                }
            }
            rez += "</table></div>";
            return rez;
        }
    }
}